// 初始化设置treeTable
function initTreeData() {
  $("#tableTree ").treetable({
    clickableNodeNames: true,
    expandable: true,
    expanderTemplate: `<a href="#" style="display:inline-block;width:17px;height:17px"></a>`,
    nodeIdAttr: "id",
    parentIdAttr: "pid",
  });

  // 突出显示选定行
  $("#tableTree tbody").on("mouseenter", "tr", function () {
    $(".selected").not(this).removeClass("selected");
    $(this).toggleClass("selected");
  });

  $("#tableTree .file, #tableTree .folder").draggable({
    helper: "clone",
    opacity: 0.75,
    refreshPositions: true,
    revert: "invalid",
    revertDuration: 300,
    scroll: true,
  });

  $("#tableTree .folder").each(function () {
    $(this)
      .parents("#tableTree tr")
      .droppable({
        accept: ".file, .folder",
        drop: function (e, ui) {
          var droppedEl = ui.draggable.parents("tr");
          $("#tableTree").treetable(
            "move",
            droppedEl.data("id"),
            $(this).data("id")
          );
        },
        hoverClass: "accept",
        over: function (e, ui) {
          var droppedEl = ui.draggable.parents("tr");
          if (this != droppedEl[0] && !$(this).is(".expanded")) {
            $("#tableTree").treetable("expandNode", $(this).data("id"));
          }
        },
      });
  });
}

// 删除节点
function del(e) {
  const id = $(e.currentTarget).attr("data-id");
  console.log(id, "ii");
}

// 修改节点
function edit(e) {
  const id = $(e.currentTarget).attr("data-id");
  console.log(id, "ii");
}
